package com.example.xunai.controller;

import com.example.xunai.entity.Admin;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class AdminController {

    @GetMapping("/admin/dashboard")
    public String adminDashboard(HttpSession session, Model model) {
        // 检查管理员登录状态
        Admin admin = (Admin) session.getAttribute("admin");
        if (admin == null) {
            return "redirect:/login";
        }

        model.addAttribute("admin", admin);
        return "admin/dashboard";
    }

    // 可以添加其他管理员功能
    @GetMapping("/admin/users")
    public String manageUsers(HttpSession session, Model model) {
        Admin admin = (Admin) session.getAttribute("admin");
        if (admin == null) {
            return "redirect:/login";
        }
        // 用户管理逻辑
        model.addAttribute("admin", admin);
        return "admin/users";
    }

    @GetMapping("/admin/settings")
    public String adminSettings(HttpSession session, Model model) {
        Admin admin = (Admin) session.getAttribute("admin");
        if (admin == null) {
            return "redirect:/login";
        }
        model.addAttribute("admin", admin);
        return "admin/settings";
    }
}